package e310

import "github.com/lishimeng/go-log"

func tagCallback(packet Packet, onTag func(pc, epc []byte, rssi byte)) {
	pc, epc, rssi := handleTag(packet)
	onTag(pc, epc, rssi)
}

func handleTag(packet Packet) (pc, epc []byte, rssi byte) {
	log.Info("handle:%02x", packet.ParameterData)
	bs := packet.ParameterData
	rssi = bs[0]
	pc = bs[1:3]
	epcByteLen := (pc[0] >> 3) * 2
	epc = bs[3 : 3+epcByteLen]
	return
}

func (c *Client) sendPacket(packet []byte, onResp func(packet Packet)) (err error) {
	_, err = c.io.Write(packet)
	if err != nil {
		return
	}
	c.respListener = onResp
	err = c.wait()
	return
}
